home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / pstex / examples / postscri.sty < prev    next >
Text File  |  1992-01-27  |  4KB  |  118 lines

  1. %
  2. % Postscriptbox and psbox macros for use with dvips and pstex.
  3. %
  4. % Neil Hunt, Schlumberger Palo Alto Research.
  5. % hunt@spar.slb.com
  6. %
  7. % HISTORY
  8. %
  9. % $Log:    postscript.sty,v $
  10. % Revision 1.5  89/01/09  13:05:38  hunt
  11. % Updated to use a single .psz file per job rather than a .tps file
  12. % for each included figure.
  13. % Revision 1.4  88/09/20  13:12:18  hunt
  14. % Cosmetic changes
  15. % Revision 1.3  88/08/04  12:33:19  hunt
  16. % A new psbox feature has been added for use with pstex:
  17. % This replaces the old psbox, and simplifies things a lot.
  18. % Revision 1.2  88/08/04  09:50:46  hunt
  19. % Added RXB's psbox hacks:
  20. % {1}    18-Apr-88  Rafael Bracho (rxb) at Schlumberger Austin Systems Center
  21. %     The postscriptbox macros were created by Neil Hunt at SPAR, I've
  22. %     added the psbox ones to use the InsertFile special.  Since I
  23. %     fixed InsertFile, I don't know if we still need the postscriptbox
  24. %     special, though.
  25. % Revision 1.1  88/08/04  09:41:01  hunt
  26. % Initial revision - useful with early embed program versions.
  27. %
  28.  
  29. %
  30. % Primitive: postscriptbox macros.
  31. % ===============================
  32. %
  33. % \postscriptbox{w}{h}{file}        Box of size w, h.
  34. % \postscriptbox(w,h){file}        Picture env. box of size w, h.
  35. %
  36.  
  37. \def \postscriptbox{\@ifnextchar ({\@postscriptpicbox}{\@postscriptbox}}
  38.  
  39. \def \@postscriptpicbox(#1,#2)#3{%
  40. \@postscriptbox{#1\unitlength}{#2\unitlength}{#3}}
  41.  
  42. \def \@postscriptbox#1#2#3{%    <width> <height> <file>
  43. \@xdim=#1\divide\@xdim 1000\multiply\@xdim\mag%
  44. \@ydim=#2\divide\@ydim 1000\multiply\@ydim\mag%
  45. \mbox{\vbox to #2{\vfil\hbox to #1%
  46. {\special{postscriptbox {\the\@xdim}{\the\@ydim}{#3}}\hfil}}}}
  47.  
  48. %
  49. % Higher level macros.
  50. % ===================
  51. %
  52. % \psbox[dimensions-options]{psfile}
  53. % 1    \psbox writes to .aux ``\psboxaux[dimensions-options]{psfile}''
  54. % 2    pstex reads .aux files, writes \pssize macros to .psz file.
  55. % 3    .psz file is input, defines size macros by figure name.
  56. % 4    \psbox invokes size macros for each figure.
  57. %
  58.  
  59. % Counters to disambiguate multiple references to the same figure.
  60. % t@psctr counts multiple occurrences of psboxaux's in .aux file.
  61. % f@psctr counts multiple occurrences of pssize's in .psz file.
  62. \newcounter{t@psctr}
  63. \newcounter{f@psctr}
  64.  
  65. \def\psbox{\@ifnextchar [{\@psbox}{\@psbox[]}}
  66.  
  67. %
  68. % First we write an entry on the aux file: psboxaux[args]{filename}
  69. % Next we generate the handle f@name used for this figure:
  70. % we check whether the tag `t@<filename>' is defined:
  71. %    If not, this is the first time PS file <filename> has been used,
  72. %    so we def \f@name = f@<filename>, and define the tag t@<filename>.
  73. %    Otherwise, this filename has been used before, and we will add
  74. %    a unique number to the name to disambiguate:
  75. %    we def \f@name = fN@<filename> where N is the value of t@psctr++.
  76. % Now we try to access the \postscriptbox macro which is the expansion
  77. % of \f@name.  If \f@name is undefined, we write a warning, and a placeholder.
  78. %
  79.  
  80. \def\@psbox[#1]#2{%
  81. \if@filesw\immediate\write\@auxout{\string\psboxaux{#1}{#2}}\fi
  82. \@ifundefined{t@#2}%
  83. {\def\f@name{f@#2}\global\@namedef{t@#2}{\relax}}%    % t@#2 undef'ed
  84. {\def\f@name{f\arabic{t@psctr}@#2}\stepcounter{t@psctr}}% t@#2 defined
  85. \@ifundefined{\f@name}{%
  86. \framebox[2in]{Figure {\tt #2}\rule[-1in]{0in}{2in}}%    % \f@name undef
  87. \@warning{Figure `#2' on page \thepage \space undefined}}%
  88. {\csname \f@name \endcsname}}                % \f@name def'd
  89.  
  90. %
  91. % Prepare to read the .aux file:
  92. %    Define psboxaux as null; it is only used as a flag for pstex.
  93. %
  94.  
  95. \let\psboxaux\@gobbletwo
  96.  
  97. %
  98. % Prepare to read the .psz file:
  99. %    Define \pssize as a macro to build f@name in an identical manner to
  100. %    above, and then define \f@name as the proper \postscriptbox macro.
  101. %
  102.  
  103. \def\pssize#1#2#3{%
  104. \@ifundefined{f@#3}%
  105. {\def\f@name{f@#3}}%                    % f@#2 undef'ed
  106. {\def\f@name{f\arabic{f@psctr}@#3}\stepcounter{f@psctr}}% f@#2 defined
  107. \global\@namedef{\f@name}{\postscriptbox{#1}{#2}{#3}}}
  108.  
  109. %
  110. % Read the .psz file to define the sizes for each figure.
  111. %
  112.  
  113. \@input{\jobname.psz}
  114.